package actives;

import java.util.HashMap;
import org.bukkit.entity.Player;

import actives.Active.ActiveState;

public class ActiveManager {
	private static HashMap<Player, HashMap<ActiveType, Active>> actives = new HashMap<Player, HashMap<ActiveType, Active>>(); 
	
	public static void prime(Player player, ActiveType active) {
		if (actives.containsKey(player) == false) {
			actives.put(player, new HashMap<ActiveType, Active>());
		}
		if (actives.get(player).containsKey(active) == false) {
			actives.get(player).put(active, ActiveType.getActive(player, active));
		}
		actives.get(player).get(active).prime();
	}

	public static void activate(Player player, ActiveType active, Object object) {
		if (actives.containsKey(player)) {
			if (actives.get(player).containsKey(active)) {
				if (actives.get(player).get(active).getState().equals(ActiveState.PRIMED)) {
					actives.get(player).get(active).activate(object);
				}
			}
		}
	}

	public static void remove(Player player) {
		if (actives.containsKey(player)) {
			for (Active active : actives.get(player).values()) {
				active.stop();
			}
			actives.remove(player);
		}
	}

	public static void remove(Player player, ActiveType active) {
		if (actives.containsKey(player)) {
			if (actives.get(player).containsKey(active)) {
				actives.get(player).get(active).stop();
				actives.get(player).remove(active);
			}
		}
	}
	
	public static ActiveState getState(Player player, ActiveType active) {
		if (actives.containsKey(player)) {
			if (actives.get(player).containsKey(active)) {
				return actives.get(player).get(active).getState();
			}
		}
		return ActiveState.READY;
	}
	
	public static int getTime(Player player, ActiveType active) {
		if (actives.containsKey(player)) {
			if (actives.get(player).containsKey(active)) {
				return actives.get(player).get(active).getTime();
			}
		}
		return 0;
	}
}
